package com.fesine.ext.controller;

import com.fesine.ext.model.Student;
import com.fesine.ext.service.StudentServiceI;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2016/10/11 10:55
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2016/10/11 10:55
 */
@Controller
@RequestMapping("/student")
public class StudentController {

    private StudentServiceI studentService;

    @Autowired
    public void setStudentService(StudentServiceI studentService) {
        this.studentService = studentService;
    }

    @RequestMapping("/{id}/show")
    public String showUser(@PathVariable Integer id, HttpServletRequest request) {
        Student student= studentService.getStudent(id);
        request.setAttribute("student", student);
        return "jsp/showStudent";
    }

    @RequestMapping("/update")
    public String updateStudent(HttpServletRequest request) {
        Integer sid = Integer.valueOf(request.getParameter("id"));
        String stuName = request.getParameter("stuName");
        String sex = request.getParameter("sex");
        Student student = new Student();
        student.setStuId(sid);
        student.setStuName(stuName);
        student.setSex(sex);
        studentService.updateStudent(student);
        request.setAttribute("student", student);
        return "jsp/showStudent";
    }
}
